# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=soqt
pkgbase=mingw-w64-${_realname}-hg
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-hg"
pkgver=r1962+.6719cfeef271+
pkgrel=1
pkgdesc="The glue between Coin & Qt (mingw-w64)"
arch=('any')
license=('BSD')
depends=("${MINGW_PACKAGE_PREFIX}-coin3d" "${MINGW_PACKAGE_PREFIX}-qt5")
makedepends=("mercurial" "${MINGW_PACKAGE_PREFIX}-cmake" "${MINGW_PACKAGE_PREFIX}-gcc")
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
url='https://bitbucket.org/Coin3D/dime'
source=("${_realname}"::"hg+https://bitbucket.org/Coin3D/soqt"
        "hg+https://bitbucket.org/Coin3D/generalmsvcgeneration"
        "hg+https://bitbucket.org/Coin3D/soanydata"
        "hg+https://bitbucket.org/Coin3D/sogui"
        001-optional-x11.patch
        003-install-pkg-config.patch)
options=(!strip staticlibs !makeflags)
sha256sums=('SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            '432f3824e71179f07020169263845b7ac59b577c4e37b85c68b8d4b7006e483e'
            '6bd87b383d23b231753ff06ca771651b05d1206732c1886b9a1b51874ea3e854')

pkgver() {
  cd "${srcdir}/${_realname}"
  printf "r%s.%s" "$(hg identify -n)" "$(hg identify -i)"
}

prepare() {
  cd ${srcdir}/${_realname}
  patch -p1 -i ${srcdir}/001-optional-x11.patch
  patch -p1 -i ${srcdir}/003-install-pkg-config.patch
}

build() {
  local -a extra_config
  if check_option "debug" "y"; then
    extra_config+=( -DCMAKE_BUILD_TYPE=Debug )
  else
    extra_config+=( -DCMAKE_BUILD_TYPE=Release )
  fi

  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}
  
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DSOQT_BUILD_SHARED_LIBS=ON \
    -DUSE_X11=OFF \
    ${extra_config} \
    ../${_realname}

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR=${pkgdir} install
}
